package weixin.app.wx.service.rest.util

import weixin.app.wx.service.rest.entities.Signature
import weixin.app.WXServiceAppFactoryDemo
import java.util.UUID
import weixin.app.wx.service.rest.util.aes.SHA1

class SignatureGenerator {
	def static Signature generate(String url) {
		
		val ticket = WXServiceAppFactoryDemo::serviceApp.getTicket
		
		val timeStamp = String.valueOf(System.currentTimeMillis() / 1000)
		
		val nonceStr = UUID.randomUUID().toString().replace("-", "").substring(0, 16)
		
		println("=====>ticket:" + ticket + "; timeStamp: " + timeStamp + "; nonceStr: " + nonceStr)
		
		new Signature()=> [
			it.signature = SHA1.getSHA1("jsapi_ticket="+ticket, "timestamp=" + timeStamp, "noncestr=" + nonceStr, "url=" + url)
			it.nonceStr = nonceStr
			it.timestamp = timeStamp
			it.appid = "wx01ad0d700af56f26"
		]
		
	}
} 